<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
        //不完全解构
        let [a, [b], d] = [1, [2, 3], 4];
        console.log(b,d) // 2 4
        var [bar, foo] = [1]; 
        // bar 1
        // foo undefined

        // 没有意义，但是符合规范
        ({} = [true, false]);
        ({} = 'abc');
        ({} = []);


        // 错误的写法
        let x2;
        // let {x2} = {x2: 1}; // 正确
        //{x2} = {x2:1};// Unexpected token '='
        //默认语法解析{} 块级作用域

        // 解决方案：加圆括号
        ({x2} = {x2:1});
        console.log(x2);// 1

        // 快速解析json
        var json = {
            "id": 1,
            "age": 15,
            "name": "TT",
            "text": "qqq",
            "user": {
                "id": 1,
                "name": "Tendo",
                "city": "FUZHOU"
            }
        }
        // json 后台传过来，只需要不完全解构就行
        let {id, text, user} = json;
        console.log(id); // 1
        console.log(text); // qqq
        console.log(user.city); // FUZHOU
    </script>
</head>
<body>
    
</body>
</html>